import { defineStore } from 'pinia'
interface Itags {
  name: string
  path: string
}
export default defineStore('tags', {
  state() {
    return {
      tagsList: [{ name: '主页', path: '/dashboard' }] as Array<Itags>,
    }
  },
  actions: {
    pushItem(payLoad: Itags) {
      if (this.tagsList.length > 0) {
        for (let item of this.tagsList) {
          if (item.name == payLoad.name) {
            // console.log('里面已经有了')
            return
          }
        }
        this.tagsList.push(payLoad)
      } else {
        this.tagsList.push(payLoad)
      }
    },
    deleteTag(payLoad: Itags) {
      let result = this.tagsList.findIndex((item) => payLoad.name == item.name)
      this.tagsList.splice(result, 1)
    },
    clearTag() {
      this.tagsList = [{ name: '主页', path: '/dashboard' }]
    },
  },
  persist: {
    enabled: true,
    strategies: [{ storage: localStorage, paths: ['tagsList'] }],
  },
})
